<?php
namespace Admin\Controller;

class UserController extends BaseController {


	public function index() {
		$this->display();
	}


	/**
	 * 获取所有用户
	 * @return [String json] [返回用户json数据文件]
	 */
	public function get_user() {

		$User = D ('User');
		$this->ajaxReturn($User->get_user());

	}

	/**
	 * 修改用户信息
	 * @return string json 返回json句柄
	 */
	public function edit() {

		if (($id = \Libs\HttpVerifyUtil::check_id()) === false) $this->ajaxReturn(array('errorMsg'=>'缺少参数'));
		
		// 获取表单信息
		$data = $_POST;
		$data['id'] = $id;
		if ($data['password'] === 'default') unset($data['password']);
		else $data['password'] = md5($data['password']);

		$User = M ('User');
		if ($flag = $User->save($data) !== false) 
			$this->ajaxReturn(array('success'=>true,'successMsg'=>'修改用户信息成功'));
		$this->ajaxReturn(array('errorMsg'=>'修改用户信息失败'));

	}


}